//package com.xiaode.controller.admin.authority;
//
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.json.JSONUtil;
//import com.jfinal.aop.Before;
//import com.jfinal.kit.Kv;
//import com.jfinal.kit.Ret;
//import com.jfinal.plugin.activerecord.Db;
//import com.jfinal.plugin.activerecord.Page;
//import com.jfinal.plugin.activerecord.Record;
//import com.jfinal.plugin.activerecord.tx.Tx;
//import com.jfinal.plugin.redis.Cache;
//import com.jfinal.plugin.redis.Redis;
//import com.xiaode.common.constant.Const;
//import com.xiaode.common.model.*;
//import com.xiaode.exce.EnumError;
//import com.xiaode.util.ChatUtil;
//
//import java.util.*;
//import java.util.stream.Collectors;
//
//public class NewAuthorityService {
//
//
//    /**
//     * 查询架构
//     *
//     * @return
//     */
//    public Ret findOrganization() {
//        Cache redis = Redis.use();
//        List<Organization> allOrganization = Organization.dao.find("SELECT id,name,authority FROM organization");
////        List<ChatGroup> chatGroups = ChatGroup.dao.find("SELECT * FROM chat_group WHERE departmentId IS NOT NULL");
////        Set<Integer> collect = chatGroups.stream().map(chatGroup -> chatGroup.getDepartmentId()).collect(Collectors.toSet());
//        allOrganization.stream().forEach(organization -> {
//            //是否创建过群聊
////            organization.put("existChatGroup", collect.contains(organization.getId()));
////            organization.put("children", new ArrayList<Organization>());
////            organization.put("admins", new ArrayList<Admin>());
////            organization.put("students", new ArrayList<Student>());
//
//            String authority = organization.getAuthority();
//            String[] s = authority.split("_");
//            organization.put("length", s.length);
//            String administrators = organization.getAdministrators();
//            List<Integer> list = JSONUtil.toList(administrators, Integer.class);
//            if (list.size() > 0) {
//                ArrayList<Admin> admins = new ArrayList<>();
//                list.stream().forEach(integer -> {
//                    Admin o = redis.get(Const.user.Admin + integer);
//                    admins.add(o);
//                });
//                organization.put("administrators", admins);
//            }
//        });
//        HashMap<String, Organization> hashMap = new HashMap<>();
//        ArrayList<Organization> organizations = new ArrayList<>();
//        HashMap<Integer, Organization> organizationHashMap = new HashMap<>();
//        int a = 1;
//        while (allOrganization.size() > 0) {
//            @SuppressWarnings("unchecked")
//			HashMap<String, Organization> clone = (HashMap<String, Organization>) hashMap.clone();
//            hashMap.clear();
//            for (int i = 0; i < allOrganization.size(); i++) {
//                Organization organization = allOrganization.get(i);
//                String authority = organization.getAuthority();
//                if (a == organization.getInt("length")) {
//                    hashMap.put(authority, organization);
//                    if (a == 1) {
//                        organizations.add(organization);
//                        allOrganization.remove(i);
//                        organizationHashMap.put(organization.getId(), organization);
//                        i--;
//                        continue;
//                    } else {
//                        Organization organization1 = clone.get(authority.substring(0, authority.lastIndexOf("_")));
//                        List<Organization> child = organization1.get("children");
//                        if (child == null) {
//                            child = new ArrayList<>();
//                        }
//                        child.add(organization);
//                        organization1.put("children", child);
//                        organizationHashMap.put(organization.getId(), organization);
//                    }
//                    allOrganization.remove(i);
//                    i--;
//                }
//            }
//            a++;
//        }
//
//        //查询教师
////        List<OrganizationUser> all = OrganizationUser.dao.findAll();
////        all.stream().forEach(organizationAdmin -> {
////            Organization organization = organizationHashMap.get(organizationAdmin.getOrganizationId());
////            //添加到organization
////            if (organizationAdmin.getUserType() == 2) {
////                List<Admin> admins = organization.get("admins");
////                Admin o = redis.get(Const.user.Admin + organizationAdmin.getUserId());
////                admins.add(o);
////            } else if (organizationAdmin.getUserType() == 1) {
////                List<Student> students = organization.get("students");
////                Student o = redis.get(Const.user.Student + organizationAdmin.getUserId());
////                o.remove("password");
////                o.remove("salt");
////                o.remove("zScore");
////                o.remove("schoolYear");
////                o.remove("lastLoginTime");
////                students.add(o);
////            }
////        });
//        return Ret.ok("organization", organizations);
//    }
//
//    /**
//     * 修改节点
//     *
//     * @param nodeId
//     * @param name
//     * @return
//     */
//    @Before(Tx.class)
//    public Ret updateNode(Integer nodeId, String name, String adList, Boolean createChatGroup, String chatGroupName) {
//        Cache redis = Redis.use();
//        List<Integer> list = JSONUtil.toList(adList, Integer.class);
//        Organization organization = Organization.dao.findById(nodeId);
//        if (list.size() == 0) {
//            return Ret.fail().set("error", EnumError.DEPARTMENT_RUNNER_NOT_ALLOW_NULL.getObj());
//        }
//        if (BeanUtil.isEmpty(organization)) {
//            return Ret.fail().set("error", EnumError.NODE_NOT_EXIT.getObj());
//        }
//        ArrayList<ChatGroupUser> groupUsers = new ArrayList<>();
//        ArrayList<Integer> arrayList = new ArrayList<>();
//        int id = 0;
//        if (createChatGroup) {
//            ChatGroup chatGroups = ChatGroup.dao.findFirst("SELECT * FROM chat_group WHERE departmentId = ?", nodeId);
//            if (BeanUtil.isNotEmpty(chatGroups)) {
//                return Ret.fail().set("error", EnumError.DEPARTMENT_HAVE_CHATGROUP.getObj());
//            }
//            ChatGroup chatGroup = new ChatGroup();
//            chatGroup.setDepartmentId(nodeId);
//            chatGroup.setVersion(1);
//            chatGroup.setLeaderId(list.get(0));
//            chatGroup.setLeaderType(2);
//            chatGroup.setType(8);
//            chatGroup.setCode(System.currentTimeMillis() + "" + list.get(0));
//            chatGroup.setName(chatGroupName == null ? name + "群" : chatGroupName);
//            chatGroup.save();
//            id = chatGroup.getId();
//            //查询当前节点下所有用户
//            List<Record> records = Db.find("SELECT ou.* FROM organization or INNER JOIN organization_user ou ON ou.organizationId = or.id WHERE or.authority like concat(?,'%')", organization.getAuthority());
//            HashSet<Integer> adSet = new HashSet<>();
//            HashSet<Integer> stuSet = new HashSet<>();
//            records.stream().forEach(record -> {
//                Integer userType = record.getInt("userType");
//                if (userType == Const.UserType.student) {
//                    stuSet.add(record.getInt("id"));
//                } else {
//                    adSet.add(record.getInt("id"));
//                }
//            });
//
//            for (int i = 0; i < list.size(); i++) {
//                Integer integer = list.get(i);
//                ChatGroupUser chatGroupUser = new ChatGroupUser();
//                chatGroupUser.setUserId(integer);
//                chatGroupUser.setUserType(2);
//                if (i == 0) {
//                    chatGroupUser.setLevel(0);
//                } else {
//                    chatGroupUser.setLevel(2);
//                }
//                Admin o = redis.get(Const.user.Admin + integer);
//                arrayList.add(o.getAccountId());
//                Integer hget = redis.hget(Const.user.Admin, integer);
//                redis.hset(Const.user.Admin, integer, hget + 1);
//                chatGroupUser.setChatGroupId(chatGroup.getId());
//                groupUsers.add(chatGroupUser);
//            }
//            for (Integer integer : adSet) {
//                Admin o = redis.get(Const.user.Admin + integer);
//                arrayList.add(o.getAccountId());
//                ChatGroupUser chatGroupUser = new ChatGroupUser();
//                chatGroupUser.setUserId(integer);
//                chatGroupUser.setUserType(2);
//                chatGroupUser.setLevel(1);
//                chatGroupUser.setChatGroupId(chatGroup.getId());
//                Integer hget = redis.hget(Const.user.Admin, integer);
//                redis.hset(Const.user.Admin, integer, hget + 1);
//                groupUsers.add(chatGroupUser);
//            }
//            for (Integer integer : stuSet) {
//                Student o = redis.get(Const.user.Student + integer);
//                arrayList.add(o.getAccountId());
//                ChatGroupUser chatGroupUser = new ChatGroupUser();
//                chatGroupUser.setUserId(integer);
//                chatGroupUser.setUserType(1);
//                chatGroupUser.setLevel(1);
//                chatGroupUser.setChatGroupId(chatGroup.getId());
//                groupUsers.add(chatGroupUser);
//            }
//        } else {
//            if (!organization.getAdministrators().equals(adList)) {
//                ChatGroup chatGroups = ChatGroup.dao.findFirst("SELECT * FROM chat_group WHERE departmentId = ?", nodeId);
//                id = chatGroups.getId();
//                if (BeanUtil.isNotEmpty(chatGroups)) {
//                    chatGroups.setLeaderId(list.get(0));
//                    for (int i = 0; i < list.size(); i++) {
//                        Integer integer = list.get(i);
//                        ChatGroupUser chatGroupUser = new ChatGroupUser();
//                        chatGroupUser.setUserId(integer);
//                        chatGroupUser.setUserType(2);
//                        if (i == 0) {
//                            chatGroupUser.setLevel(0);
//                        } else {
//                            chatGroupUser.setLevel(2);
//                        }
//                        Admin o = redis.get(Const.user.Admin + integer);
//                        arrayList.add(o.getAccountId());
//                        chatGroupUser.setChatGroupId(chatGroups.getId());
//                        groupUsers.add(chatGroupUser);
//                    }
//                    Db.delete("DELETE FROM chat_group_user WHERE chatGroupId = ? AND level != 1", chatGroups.getId());
//                }
//            }
//        }
//        ChatUtil.addGroupsByGroupId(id, arrayList);
//
//        if (!organization.getAdministrators().equals(adList)) {
//            String administrators = organization.getAdministrators();
//            List<Integer> integers = JSONUtil.toList(administrators, Integer.class);
//            list.removeAll(integers);
//            if (list.size() > 0) {
//                List<Integer> parentNodeId = getParentNodeId(organization);
//                List<Integer> collect = parentNodeId.stream().filter(integer -> !organization.getId().equals(integer)).collect(Collectors.toList());
//                Kv kv = Kv.by("nodeIdList", collect);
//                List<ChatGroup> records = ChatGroup.dao.template("findChatGroupByDepartmentIds", kv).find();
//                for (ChatGroup record : records) {
//                    arrayList.clear();
//                    List<ChatGroupUser> chatGroupUsers = ChatGroupUser.dao.find("SELECT userId FROM chat_user_group WHERE chatGroupId = ? AND userType = 2", record.getId());
//                    Set<Integer> set = chatGroupUsers.stream().map(chatGroupUser -> chatGroupUser.getUserId()).collect(Collectors.toSet());
//                    for (Integer integer : list) {
//                        if (!set.contains(integer)) {
//                            ChatGroupUser chatGroupUser = new ChatGroupUser();
//                            chatGroupUser.setUserId(integer);
//                            chatGroupUser.setUserType(2);
//                            chatGroupUser.setLevel(1);
//                            chatGroupUser.setChatGroupId(record.getId());
//                            groupUsers.add(chatGroupUser);
//                            Admin o = redis.get(Const.user.Admin + integer);
//                            arrayList.add(o.getAccountId());
//                        }
//                    }
//                    ChatUtil.addGroupsByGroupId(record.getId(), arrayList);
//                }
//            }
//        }
//        Db.batchSave(groupUsers, groupUsers.size());
//
//        //处理父节点群中
//        organization.setName(name);
//        organization.setAdministrators(adList);
//        organization.update();
//        return Ret.ok();
//    }
//
//    /**
//     * 节点成员管理
//     *
//     * @param nodeId
//     * @param adIdList
//     * @return
//     */
//    @Before(Tx.class)
//    public Ret nodeMemberManage(Integer nodeId, String adIdList, String stuIdList) {
//        Cache redis = Redis.use();
//        Organization organization = Organization.dao.findById(nodeId);
//        if (BeanUtil.isEmpty(organization)) {
//            return Ret.fail().set("error", EnumError.NODE_NOT_EXIT.getObj());
//        }
//        //用来发送聊天服务器集合
//        ArrayList<Integer> arrayList = new ArrayList<>();
//        ArrayList<OrganizationUser> organizationAdmins = new ArrayList<>();
//        List<Integer> list = JSONUtil.toList(adIdList, Integer.class);
//        List<Integer> integers = JSONUtil.toList(stuIdList, Integer.class);
//        list.stream().forEach(integer -> {
//            OrganizationUser organizationAdmin = new OrganizationUser();
//            organizationAdmin.setUserId(integer);
//            organizationAdmin.setUserType(2);
//            organizationAdmin.setOrganizationId(nodeId);
//            organizationAdmins.add(organizationAdmin);
//        });
//        integers.stream().forEach(integer -> {
//                    OrganizationUser organizationAdmin = new OrganizationUser();
//                    organizationAdmin.setUserId(integer);
//                    organizationAdmin.setUserType(1);
//                    organizationAdmin.setOrganizationId(nodeId);
//                    organizationAdmins.add(organizationAdmin);
//                }
//        );
//
//        List<Integer> nodeIdList = getParentNodeId(organization);
//        Kv kv = Kv.by("nodeIdList", nodeIdList);
//        List<ChatGroup> records = ChatGroup.dao.template("findChatGroupByDepartmentIds", kv).find();
//        if (records.size() > 0) {
//            ArrayList<ChatGroupUser> chatGroupUsers = new ArrayList<>();
//            for (ChatGroup record : records) {
//                arrayList.clear();
//                Integer id = record.getId();
//                for (Integer integer : list) {
//                    ChatGroupUser chatGroupUser = new ChatGroupUser();
//                    chatGroupUser.setUserId(integer);
//                    chatGroupUser.setUserType(2);
//                    chatGroupUser.setLevel(1);
//                    chatGroupUser.setChatGroupId(id);
//                    chatGroupUsers.add(chatGroupUser);
//                    Admin o = redis.get(Const.user.Admin + integer);
//                    arrayList.add(o.getAccountId());
//                }
//                for (Integer integer : integers) {
//                    ChatGroupUser chatGroupUser = new ChatGroupUser();
//                    chatGroupUser.setUserId(integer);
//                    chatGroupUser.setUserType(1);
//                    chatGroupUser.setLevel(1);
//                    chatGroupUser.setChatGroupId(id);
//                    chatGroupUsers.add(chatGroupUser);
//                    Student o = redis.get(Const.user.Student + integer);
//                    arrayList.add(o.getAccountId());
//                }
//                ChatUtil.addGroupsByGroupId(id, arrayList);
//                record.setVersion(record.getVersion() + 1);
//            }
//            Db.batchUpdate(records, records.size());
//            Db.batchSave(chatGroupUsers, chatGroupUsers.size());
//        }
//
//        //删除原有成员
//        Db.delete("DELETE FROM organization_user WHERE organizationId = ?", nodeId);
//        Db.batchSave(organizationAdmins, organizationAdmins.size());
//        return Ret.ok();
//    }
//
//    /**
//     * 删除节点
//     *
//     * @param nodeId
//     * @return
//     */
//    @Before(Tx.class)
//    public Ret delNode(Integer nodeId) {
//        Organization organization = Organization.dao.findById(nodeId);
//        if (BeanUtil.isEmpty(organization)) {
//            return Ret.fail().set("error", EnumError.NODE_NOT_EXIT.getObj());
//        }
//        //判断节点下是否有学生
//        List<Organization> organizations = Organization.dao.find("SELECT * FROM organization WHERE authority like concat(?,'%')", organization.getAuthority());
//        List<Integer> collect = organizations.stream().map(organization1 -> organization1.getId()).collect(Collectors.toList());
//        if (collect.size() > 0) {
//            Kv kv = Kv.create().set("organizationIdList", collect);
//            //删除节点下绑定成员
//            Db.template("deleteOrganizationUserByOrganizationIds", kv).delete();
//            Db.template("deleteOrganizationByIds", kv).delete();
//        }
//        return Ret.ok();
//    }
//
//    /**
//     * 添加节点
//     *
//     * @param name
//     * @param parentNodeId
//     * @return
//     */
//    @Before(Tx.class)
//    public Ret addNode(String name, Integer parentNodeId, String adList, Boolean createChatGroup, String chatName) {
//        Cache redis = Redis.use();
//        Organization newOrganization = new Organization();
//        List<Integer> integers = JSONUtil.toList(adList, Integer.class);
//        if (integers.size() == 0) {
//            return Ret.fail().set("error", EnumError.DEPARTMENT_RUNNER_NOT_ALLOW_NULL.getObj());
//        }
//        //IM聊天服务用的集合
//        ArrayList<Integer> arrayList = new ArrayList<>();
//        newOrganization.setName(name);
//        newOrganization.setAdministrators(adList);
//        if (BeanUtil.isNotEmpty(parentNodeId)) {
//            Organization organization = Organization.dao.findById(parentNodeId);
//            if (BeanUtil.isEmpty(organization)) {
//                return Ret.fail().set("error", EnumError.PAENT_NODE_NOT_EXIT.getObj());
//            }
//            newOrganization.setAuthority(organization.getAuthority() + "_");
//        } else {
//            //如果没有根节点
//            newOrganization.setAuthority("");
//        }
//        newOrganization.save();
//        newOrganization.setAuthority(newOrganization.getAuthority() + newOrganization.getId());
//        newOrganization.update();
//        ArrayList<ChatGroupUser> chatGroupUsers = new ArrayList<>();
//        //如果要创建群聊
//        if (createChatGroup) {
//            ChatGroup chatGroup = new ChatGroup();
//            chatGroup.setVersion(1);
//            chatGroup.setLeaderId(integers.get(0));
//            chatGroup.setLeaderType(2);
//            chatGroup.setType(8);
//            chatGroup.setName(chatName == null ? name + "群" : chatName);
//            chatGroup.setDepartmentId(newOrganization.getId());
//            chatGroup.setCode(System.currentTimeMillis() + "" + newOrganization.getId());
//            chatGroup.save();
//
//            for (int i = 0; i < integers.size(); i++) {
//                Integer integer = integers.get(i);
//                ChatGroupUser chatGroupUser = new ChatGroupUser();
//                if (i == 0) {
//                    chatGroupUser.setLevel(0);
//                } else {
//                    chatGroupUser.setLevel(2);
//                }
//                chatGroupUser.setUserId(integer);
//                chatGroupUser.setUserType(2);
//                chatGroupUser.setChatGroupId(chatGroup.getId());
//                chatGroupUsers.add(chatGroupUser);
//                Admin o = redis.get(Const.user.Admin + integer);
//                arrayList.add(o.getAccountId());
//            }
//            ChatUtil.addGroupsByGroupId(chatGroup.getId(), arrayList);
//        }
//
//        List<Integer> parentNodeIdList = getParentNodeId(newOrganization);
//        List<Integer> collect = parentNodeIdList.stream().filter(integer -> !newOrganization.getId().equals(integer)).collect(Collectors.toList());
//        Kv kv = Kv.by("nodeIdList", collect);
//        List<ChatGroup> records = ChatGroup.dao.template("findChatGroupByDepartmentIds", kv).find();
//        for (ChatGroup record : records) {
//            arrayList.clear();
//            List<ChatGroupUser> chatGroupUserList = ChatGroupUser.dao.find("SELECT userId FROM chat_user_group WHERE chatGroupId = ? AND userType = 2", record.getId());
//            Set<Integer> set = chatGroupUserList.stream().map(chatGroupUser -> chatGroupUser.getUserId()).collect(Collectors.toSet());
//            for (Integer integer : integers) {
//                if (!set.contains(integer)) {
//                    ChatGroupUser chatGroupUser = new ChatGroupUser();
//                    chatGroupUser.setUserId(integer);
//                    chatGroupUser.setUserType(2);
//                    chatGroupUser.setLevel(1);
//                    chatGroupUser.setChatGroupId(record.getId());
//                    chatGroupUsers.add(chatGroupUser);
//                    Admin o = redis.get(Const.user.Admin + integer);
//                    arrayList.add(o.getAccountId());
//                }
//            }
//            ChatUtil.addGroupsByGroupId(record.getId(), arrayList);
//            record.setVersion(record.getVersion() + 1);
//        }
//
//        Db.batchSave(chatGroupUsers, chatGroupUsers.size());
//        Db.batchUpdate(records, records.size());
//        return Ret.ok();
//    }
//
//    /**
//     * 返回父类节点id
//     *
//     * @return
//     */
//    public List<Integer> getParentNodeId(Organization organization) {
//        String authority = organization.getAuthority();
//        String[] s = authority.split("_");
//        ArrayList<String> strings = new ArrayList<>();
//        String str = null;
//        for (int i = 0; i < s.length; i++) {
//            String s1 = s[i];
//            if (i == 0) {
//                str = s1;
//                String a = str;
//                strings.add(a);
//            } else {
//                str += "_" + s1;
//                String a = str;
//                strings.add(a);
//            }
//        }
//        Kv kv = Kv.by("authoritys", strings);
//        List<Record> recordList = Db.template("findOrganizationByAuthority", kv).find();
//        List<Integer> id = recordList.stream().map(record -> record.getInt("id")).collect(Collectors.toList());
//        return id;
//    }
//
//    /**
//     * 根据节点查询成员
//     *
//     * @param nodeId
//     * @param keyWord
//     * @return
//     */
//    public Ret findNodeMember(Integer nodeId, String keyWord, Integer page, Integer limit) throws Exception {
//        Cache redis = Redis.use();
//        //查询当前节点
//        Organization organization = Organization.dao.findById(nodeId);
//        if (BeanUtil.isEmpty(organization)){
//            return Ret.fail().set("error",EnumError.NODE_NOT_EXIT.getObj());
//        }
//        String authority = organization.getAuthority();
//        //查询当前节点与其子节点
//        List<Organization> organizationList = Organization.dao.find("SELECT * FROM organization WHERE authority like concat(?,'%')", authority);
//        List<Integer> list = organizationList.stream().map(organization1 -> organization1.getId()).collect(Collectors.toList());
//        Kv kv = Kv.by("nodeIdList", list).setIfNotNull("keyWord", keyWord);
//        ArrayList<Record> records = new ArrayList<>();
//        int sum = 0;
//        int totalRow = 0;
//        if (keyWord != null) {
//            //如果关键字不为空
//            List<Record> adList = Db.template("findAdminByKeyWordAndOrganizationId", kv).find();
//            adList.stream().forEach(record -> record.put("type", 2));
//            List<Record> stuList = Db.template("findStuByKeyWordAndOrganizationId", kv).find();
//            stuList.stream().forEach(record -> record.put("type", 1));
//            adList.addAll(stuList);
//            int size = adList.size();
//            List<Record> resList = adList.stream().skip((page - 1) * limit).limit(limit).collect(Collectors.toList());
//            //处理数据
//            resList.stream().forEach(record -> {
//                Integer type = record.getInt("type");
//                if (type == 2) {
//                    Admin o = redis.get(Const.user.Admin + record.getInt("id"));
//                    record.put("name", o.getName());
//                    record.put("pic", o.getAvatarUrl());
//                    record.put("state", o.getState());
//                    record.put("sex", null);
//                    record.put("clasId", null);
//                    record.put("superior", null);
//                } else if (type == 1) {
//                    Student o = redis.get(Const.user.Student + record.getInt("id"));
//                    record.put("name", o.getName());
//                    record.put("sex", o.getSex());
//                    record.put("pic", o.getAvatarUrl());
//                    record.put("state", o.getState());
//                    record.put("clasId", o.getClasId());
//                    record.put("superior", o.getStr("teacher"));
//                }
//            });
//            return Ret.ok().set("records", resList).set("page", page).set("count", size % limit == 0 ? size / limit : size / limit + 1).set("totalRow", size);
//        } else {
//            //关键词为空
//            Page<OrganizationUser> orPage = OrganizationUser.dao.template("findOrganizationUserByNodeIdList", kv).paginate(page, limit);
//            List<OrganizationUser> users = orPage.getList();
//            sum = orPage.getTotalPage();
//            totalRow = users.size();
//            //遍历处理用户数据
//            users.stream().forEach(organizationUser -> {
//                Integer userType = organizationUser.getUserType();
//                if (userType == Const.UserType.student) {
//                    Record record = new Record();
//                    Student o = redis.get(Const.user.Student + organizationUser.getUserId());
//                    record.put("name", o.getName());
//                    record.put("id", organizationUser.getUserId());
//                    record.put("sex", o.getSex());
//                    record.put("pic", o.getAvatarUrl());
//                    record.put("state", o.getState());
//                    record.put("clasId", o.getClasId());
//                    record.put("superior", o.getStr("teacher"));
//                    records.add(record);
//                } else if (userType == Const.UserType.admin) {
//                    Record record = new Record();
//                    Admin o = redis.get(Const.user.Admin + organizationUser.getUserId());
//                    record.put("name", o.getName());
//                    record.put("id", organizationUser.getUserId());
//                    record.put("pic", o.getAvatarUrl());
//                    record.put("state", o.getState());
//                    record.put("sex", null);
//                    record.put("clasId", null);
//                    record.put("superior", null);
//                    records.add(record);
//                }
//            });
//        }
//
//
//        return Ret.ok().set("records", records).set("count", sum).set("page", page).set("totalRow", totalRow);
//    }
//
//    public Ret delMember(Integer userId, Integer userType) {
//        Cache redis = Redis.use();
//        //如果用户是学生,删除学生信息
//        if (userType == Const.UserType.student){
//            Student student = Student.dao.findById(userId);
//            student.setIsDele(true);
//            student.setZScore(0);
//            student.update();
//            redis.del(Const.user.Student + userId);
//            redis.del(Const.user.loginStudent + student.getAccountId());
//            redis.zrem(Const.user.StudentScore,student.getId());
//            //删除与教师绑定关系
//            Db.delete("DELETE FEOM teacher_student WHERE studentId = ?",userId);
//        }else if(userType == Const.UserType.admin){
//            //删除教师信息
//            Admin admin = Admin.dao.findById(userId);
//            admin.setIsDele(true);
//            admin.update();
//            redis.del(Const.user.Admin + userId);
//            redis.del(Const.user.loginAdmin + admin.getAccountId());
//            Db.delete("DELETE FROM teacher_student WHERE teacherId = ?",userId);
//            Db.delete("DELETE FROM data_permission WHERE  teacherId = ?",userId);
//            Db.delete("DELETE FROM org_admin WHERE teacherId = ?",userId);
//        }
//        Db.delete("DELETE FROM organization_user WHERE userId = ? AND userType = ?",userId,userType);
//        Db.delete("DELETE FROM friends WHERE (userId = ? AND userType = ?) OR (userId2 = ? AND userType2 = ?)",userId,userType,userId,userType);
//        Db.update("UPDATE chat_group SET leaderId = null ,leaderType = null WHERE leaderId = ? AND leaderType = ?",userId,userType);
//        Db.delete("DELETE FROM chat_group_user WHERE userId = ? AND userType = ?",userId,userType);
//        return Ret.ok();
//    }
//}
